package cn.zz.camerasdk.filter.ifilter;

/**
 * author: zhu on 2017/7/7 17:26
 * email: mackkill@gmail.com
 */

import android.content.Context;

import cn.zz.camerasdk.utils.MResource;

public class IFHudsonFilter extends IFImageFilter {
    private static final String SHADER = "precision lowp float;\n \n varying highp vec2 textureCoordinate;\n \n uniform sampler2D inputImageTexture;\n uniform sampler2D inputImageTexture2; //blowout;\n uniform sampler2D inputImageTexture3; //overlay;\n uniform sampler2D inputImageTexture4; //map\n \n void main()\n {\n     \n     vec4 texel = texture2D(inputImageTexture, textureCoordinate);\n     \n     vec3 bbTexel = texture2D(inputImageTexture2, textureCoordinate).rgb;\n     \n     texel.r = texture2D(inputImageTexture3, vec2(bbTexel.r, texel.r)).r;\n     texel.g = texture2D(inputImageTexture3, vec2(bbTexel.g, texel.g)).g;\n     texel.b = texture2D(inputImageTexture3, vec2(bbTexel.b, texel.b)).b;\n     \n     vec4 mapped;\n     mapped.r = texture2D(inputImageTexture4, vec2(texel.r, .16666)).r;\n     mapped.g = texture2D(inputImageTexture4, vec2(texel.g, .5)).g;\n     mapped.b = texture2D(inputImageTexture4, vec2(texel.b, .83333)).b;\n     mapped.a = 1.0;\n     gl_FragColor = mapped;\n }\n";

    public IFHudsonFilter(Context context) {
        super(context, "precision lowp float;\n \n varying highp vec2 textureCoordinate;\n \n uniform sampler2D inputImageTexture;\n uniform sampler2D inputImageTexture2; //blowout;\n uniform sampler2D inputImageTexture3; //overlay;\n uniform sampler2D inputImageTexture4; //map\n \n void main()\n {\n     \n     vec4 texel = texture2D(inputImageTexture, textureCoordinate);\n     \n     vec3 bbTexel = texture2D(inputImageTexture2, textureCoordinate).rgb;\n     \n     texel.r = texture2D(inputImageTexture3, vec2(bbTexel.r, texel.r)).r;\n     texel.g = texture2D(inputImageTexture3, vec2(bbTexel.g, texel.g)).g;\n     texel.b = texture2D(inputImageTexture3, vec2(bbTexel.b, texel.b)).b;\n     \n     vec4 mapped;\n     mapped.r = texture2D(inputImageTexture4, vec2(texel.r, .16666)).r;\n     mapped.g = texture2D(inputImageTexture4, vec2(texel.g, .5)).g;\n     mapped.b = texture2D(inputImageTexture4, vec2(texel.b, .83333)).b;\n     mapped.a = 1.0;\n     gl_FragColor = mapped;\n }\n");
        this.setRes(context);
    }

    private void setRes(Context context) {
        int resId1 = MResource.getIdByName(context, "drawable", "hudson_background");
        int resId2 = MResource.getIdByName(context, "drawable", "overlay_map");
        int resId3 = MResource.getIdByName(context, "drawable", "hudson_map");
        this.addInputTexture(resId1);
        this.addInputTexture(resId2);
        this.addInputTexture(resId3);
    }
}
